﻿
namespace Huirui.Cavan.Application.Seedwork
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;
    using System.Linq;
    using Huirui.Cavan.Core.Persistent;

    /// <summary>
    ///     Provides similar Entity (of type T) CRUD methods
    ///     as Dao. They must take care about Business rules
    /// </summary>
    /// <typeparam name = "T"></typeparam>
    /// <typeparam name = "TID"></typeparam>
    /// <typeparam name = "TSearch"></typeparam>
    public interface IReadAppService<out T, in TID, in TSearch> : IReadAppService<T, TID>
        where T : class, IPersistentObjectWithTypedId<TID>
        where TSearch : class, ISearch<TID>
    {
        IEnumerable<T> GetBySearch(TSearch searchParams);
        T GetSingleBySearch(TSearch searchParams);
        IEnumerable<T> GetBySearch(TSearch searchParams, out long total);
        long GetCount(TSearch searchParams);
    }

    public interface IReadAppService<out T, in TID> : IAppService
        where T : class, IPersistentObjectWithTypedId<TID>
    {
        /// <summary>
        ///     Basic read operation for getting known entity
        /// </summary>
        /// <param name = "id">Entity unique int identifier</param>
        /// <returns>Entity instance or null</returns>
        T GetById(TID id);
    }
}